package com.ruoyi.elebook.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.elebook.domain.BookCatalogScope;
import com.ruoyi.elebook.service.IBookCatalogScopeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 目录范围Controller
 * 
 * @author ruoyi
 * @date 2023-12-11
 */
@RestController
@RequestMapping("/scope")
public class BookCatalogScopeController extends BaseController
{
    @Autowired
    private IBookCatalogScopeService bookCatalogScopeService;

    /**
     * 查询目录范围列表
     */
    @RequiresPermissions("elebook:scope:list")
    @GetMapping("/list")
    public TableDataInfo list(BookCatalogScope bookCatalogScope)
    {
        startPage();
        List<BookCatalogScope> list = bookCatalogScopeService.selectBookCatalogScopeList(bookCatalogScope);
        return getDataTable(list);
    }

    /**
     * 导出目录范围列表
     */
    @RequiresPermissions("elebook:scope:export")
    @Log(title = "目录范围", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BookCatalogScope bookCatalogScope)
    {
        List<BookCatalogScope> list = bookCatalogScopeService.selectBookCatalogScopeList(bookCatalogScope);
        ExcelUtil<BookCatalogScope> util = new ExcelUtil<BookCatalogScope>(BookCatalogScope.class);
        util.exportExcel(response, list, "目录范围数据");
    }

    /**
     * 获取目录范围详细信息
     */
    @RequiresPermissions("elebook:scope:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bookCatalogScopeService.selectBookCatalogScopeById(id));
    }

    /**
     * 新增目录范围
     */
    @RequiresPermissions("elebook:scope:add")
    @Log(title = "目录范围", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BookCatalogScope bookCatalogScope)
    {
        return toAjax(bookCatalogScopeService.insertBookCatalogScope(bookCatalogScope));
    }

    /**
     * 修改目录范围
     */
    @RequiresPermissions("elebook:scope:edit")
    @Log(title = "目录范围", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BookCatalogScope bookCatalogScope)
    {
        return toAjax(bookCatalogScopeService.updateBookCatalogScope(bookCatalogScope));
    }

    /**
     * 删除目录范围
     */
    @RequiresPermissions("elebook:scope:remove")
    @Log(title = "目录范围", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bookCatalogScopeService.deleteBookCatalogScopeByIds(ids));
    }
}
